package com.ruoyi.web.controller.drug;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.drug.domain.DrugsDurg;
import com.ruoyi.drug.service.IDrugsDurgService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品Controller
 *
 * @author ruoyi
 * @date 2022-11-13
 */
@RestController
@RequestMapping("/drug/drug")
public class DrugsDurgController extends BaseController
{
    @Autowired
    private IDrugsDurgService drugsDurgService;

    /**
     * 查询药品列表
     */
    @PreAuthorize("@ss.hasPermi('system:durg:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugsDurg drugsDurg)
    {
        startPage();
        List<DrugsDurg> list = drugsDurgService.selectDrugsDurgList(drugsDurg);
        return getDataTable(list);
    }

    /**
     * 导出药品列表
     */
    @PreAuthorize("@ss.hasPermi('system:durg:export')")
    @Log(title = "药品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugsDurg drugsDurg)
    {
        List<DrugsDurg> list = drugsDurgService.selectDrugsDurgList(drugsDurg);
        ExcelUtil<DrugsDurg> util = new ExcelUtil<DrugsDurg>(DrugsDurg.class);
        util.exportExcel(response, list, "药品数据");
    }

    /**
     * 获取药品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:durg:query')")
    @GetMapping(value = "/{durgId}")
    public AjaxResult getInfo(@PathVariable("durgId") Long durgId)
    {
        return success(drugsDurgService.selectDrugsDurgByDurgId(durgId));
    }

    /**
     * 新增药品
     */
    @PreAuthorize("@ss.hasPermi('system:durg:add')")
    @Log(title = "药品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugsDurg drugsDurg)
    {
        return toAjax(drugsDurgService.insertDrugsDurg(drugsDurg));
    }

    /**
     * 修改药品
     */
    @PreAuthorize("@ss.hasPermi('system:durg:edit')")
    @Log(title = "药品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugsDurg drugsDurg)
    {
        return toAjax(drugsDurgService.updateDrugsDurg(drugsDurg));
    }

    /**
     * 删除药品
     */
    @PreAuthorize("@ss.hasPermi('system:durg:remove')")
    @Log(title = "药品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{durgIds}")
    public AjaxResult remove(@PathVariable Long[] durgIds)
    {
        return toAjax(drugsDurgService.deleteDrugsDurgByDurgIds(durgIds));
    }
}
